home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume8 / checkfiles < prev    next >
Encoding:
Text File  |  1989-11-02  |  13.5 KB  |  574 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v08i099: checkfiles for comp.sources.misc
  3. from: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  4. Reply-To: mpb@osf.org (Paul Blackburn)
  5.  
  6. Posting-number: Volume 8, Issue 99
  7. Submitted-by: mpb@osf.org (Paul Blackburn)
  8. Archive-name: checkfiles
  9.  
  10. Here is 'checkfiles', a script for keeping track of changes to
  11. files. System administrators may find this useful to have unwanted
  12. or unexpected changes to files reported to them.
  13.  
  14. Paul Blackburn,                            "live free or die..."
  15. Open Software Foundation, European Development, Munich, West Germany
  16. mail: mpb@osf.de Internet: mpb@mn.osf.org uucp: ..uunet!mcvax!unido!osfmuc!mpb
  17. ------------------------------cut here----------coupe ici-----------
  18. #! /bin/sh
  19. # This is a shell archive, meaning:
  20. # 1. Remove everything above the #! /bin/sh line.
  21. # 2. Save the resulting text in a file.
  22. # 3. Execute the file with /bin/sh (not csh) to create the files:
  23. #    checkfiles
  24. # This archive created: Tue Oct 31 16:54:39 1989
  25. # By:    Paul Blackburn (Open Software Foundation, European Development, Munich)
  26. export PATH; PATH=/bin:$PATH
  27. if test ! -d 'checkfiles'
  28. then
  29.     echo shar: creating directory "'checkfiles'"
  30.     mkdir 'checkfiles'
  31. fi
  32. echo shar: entering directory "'checkfiles'"
  33. cd 'checkfiles'
  34. echo shar: extracting "'Makefile'" '(85 characters)'
  35. if test -f 'Makefile'
  36. then
  37.     echo shar: will not over-write existing file "'Makefile'"
  38. else
  39. sed 's/^X//' << \SHAR_EOF > 'Makefile'
  40. X# Makefile to build ftype
  41. X
  42. Xftype:    ftype.c Makefile
  43. X    $(CC) $(CFLAGS) -o ftype ftype.c
  44. SHAR_EOF
  45. fi # end of overwriting check
  46. echo shar: extracting "'README'" '(3430 characters)'
  47. if test -f 'README'
  48. then
  49.     echo shar: will not over-write existing file "'README'"
  50. else
  51. sed 's/^X//' << \SHAR_EOF > 'README'
  52. XIntroduction:
  53. X
  54. Xcheckfiles is a shellscript to check for changes to a set of
  55. Xfiles and report differences by mail.
  56. X
  57. XProblem:
  58. X
  59. XI want to know when certain files have been changed but I don't want to
  60. Xhave to check them out myself because it takes me too long.
  61. X
  62. XAs systems administrator I have to know if /bin/login changes
  63. Xespecially if I did not change it!
  64. X
  65. XSolution:
  66. X
  67. XHave a program do the checking for me and mail me the changes.
  68. XUse a list of files to be checked and keep 'original' copies :-)
  69. Xto check current versions against.
  70. X
  71. XThe tools I use to do this are:
  72. X
  73. Xresetfiles    - Update the reference copy of files
  74. Xcheckfiles    - find out if any changes, mail the results
  75. Xftype        - Determine is file is a binary (not diff'able)
  76. X
  77. XEnvironment:
  78. X
  79. XThese Bourne shellscripts have been tested under ULTRIX and
  80. Xshould (let me know if otherwise) run under most UNIXes.
  81. XThe tools are Bourne shellscripts and 'make' is also used.
  82. X
  83. XHow to install:
  84. X
  85. Xa) run a 'make' to compile ftype.c.
  86. X
  87. Xb) Edit the file 'list' to reflect the files you need to check.
  88. X   I haven't used a huge list yet, it seems a good idea to keep the 
  89. X   list short.
  90. X
  91. Xc) Define where the reference copies are to be held. Edit both
  92. X   checkfiles and resetfiles and change the value of BASE to
  93. X   the current directory.
  94. X
  95. Xd) To avoid problems of checkfiles running on the wrong host
  96. X   edit both checkfiles and resetfiles and set MASTER to the hostname
  97. X   it should only run on. There was a problem using checkfiles in a
  98. X   configuration with many workstations sharing the same (remote)
  99. X   filestore.
  100. X
  101. Xe) Define who should receive mail about any changes to the files.
  102. X   Edit 'checkfiles' and change NOTIFY to your requirement.
  103. X
  104. Xf) Run a 'resetfiles' to create your reference copy of file(s) from 'list'.
  105. X   These are stored under $BASE/originals.
  106. X
  107. Xg) Run a 'checkfiles', you should get:
  108. X
  109. X    0 files changed
  110. X
  111. Xh) Set up a crontab entry to run checkfiles as often as you wish.
  112. X   Here is an example entry for crontab to run each hour:
  113. X
  114. X0 * * * * /usr/local/bin/checkfiles >> /usr/lib/cronlog
  115. X
  116. X   I use the excellent 'watcher' program [1] that was distributed
  117. X   over USENET to invoke 'checkfiles'.
  118. X
  119. X   Here is an example entry for a Watcherfile:
  120. X
  121. X(/usr/local/bin/checkfiles) { 'file changes' }
  122. X    1 count%d 2 file%s 3 changed%s:
  123. X        count 0 0.
  124. X
  125. XUsing checkfiles:
  126. X
  127. XWhen checkfiles reports some change(s) to a file you have to decide
  128. Xwhether the change is OK or not. If you are happy with the change then
  129. Xrun a 'resetfiles' to update the reference copy otherwise you will
  130. Xcontinue to receive notification about the change every time you
  131. Xrun checkfiles.
  132. X
  133. Xcheckfiles reports on changes to binary files by giving checksum information
  134. Xand changes to non-binary files by providing 'diff' output.
  135. X
  136. XDo be careful about the location and access rights to the 'originals'
  137. Xdirectory. If an intruder found this (s)he would of course change
  138. Xboth the current file and the one in 'originals'.
  139. X
  140. XReferences:
  141. X
  142. X[1] watcher by Kenneth Ingham,
  143. X    University of New Mexico Computing Center,
  144. X    2701 Campus NE,
  145. X    Alburquerque, NM, 87131
  146. X    ingham@charon.unm.edu or ucbvax!unmvax!charon!ingham
  147. XCaveat: not guaranteed for anything but fun to run
  148. X
  149. XAuthor:
  150. X
  151. XPaul Blackburn,                                 "live free or die..."
  152. XOpen Software Foundation, Stefan-George-Ring 29, D-8000 Munich 81, W Germany
  153. XMail: mpb@osf.de, mpb@mn.osf.org, ..uunet!mcvax!unido!osfmuc!mpb
  154. XTel: +49-89-93092-123 Fax: +49-89-93092-104
  155. SHAR_EOF
  156. fi # end of overwriting check
  157. echo shar: extracting "'checkfiles'" '(1964 characters)'
  158. if test -f 'checkfiles'
  159. then
  160.     echo shar: will not over-write existing file "'checkfiles'"
  161. else
  162. sed 's/^X//' << \SHAR_EOF > 'checkfiles'
  163. X#!/bin/sh5
  164. X# NAME        checkfiles
  165. X# AUTHOR    Paul Blackburn, OSF, Munich
  166. X# DATE        Sat Oct 21 11:52:05 MET 1989
  167. X# PURPOSE    Compares originals with current, reports diffs
  168. X
  169. XPATH=/usr/ucb:/bin:/usr/bin
  170. Xexport PATH
  171. XIFS="     
  172. X"
  173. Xexport IFS
  174. X
  175. XBASE=/users/mpb/masters
  176. XNOTIFY=mpb
  177. XMASTER=osfmuc
  178. X
  179. XLIST=${BASE}/list
  180. XODIR=originals
  181. XORIG=${BASE}/${ODIR}
  182. XMAKE=${BASE}/Makefile.re
  183. XTMP1=/usr/tmp/check1.$$
  184. XTMP2=/usr/tmp/check2.$$
  185. XTMP3=/usr/tmp/check3.$$
  186. X
  187. XCMD=`basename ${0}`
  188. X
  189. Xif [ "${MASTER}" != "`uuname -l`" ]
  190. Xthen
  191. X    echo "Error: ${CMD} should be executed on ${MASTER}" >&2
  192. X    exit 1
  193. Xfi
  194. X
  195. Xif [ -d "${BASE}" ]
  196. Xthen
  197. X    cd $BASE
  198. Xelse
  199. X    echo "${CMD}: unable to cd to ${BASE}" >&2
  200. X    exit 1
  201. Xfi
  202. X
  203. X# Create a Makefile from LIST
  204. X
  205. Xif [ ! -z "${DEBUG}" ]
  206. Xthen
  207. X    echo "Creating list of files"
  208. Xfi
  209. X
  210. Xgrep -v "^#" <$LIST \
  211. X| sed -e "/^$/d" \
  212. X| cut -c2- >${TMP1}
  213. X
  214. Xif [ ! -z "${DEBUG}" ]
  215. Xthen
  216. X    echo "Checking current versus original"
  217. Xfi
  218. X
  219. Xwhile FILE=`line`
  220. Xdo
  221. X    CFILE=/${FILE}
  222. X    OFILE=${ORIG}/${FILE}
  223. X    cmp ${OFILE} ${CFILE} 2>&1 >/dev/null
  224. X    if [ $? = 1 ]
  225. X    then
  226. X        if [ ! -z "${DEBUG}" ]
  227. X        then
  228. X            echo "/${FILE} changed"
  229. X        fi
  230. X
  231. X        echo ${FILE} >>${TMP3}
  232. X    fi
  233. Xdone <${TMP1}
  234. X
  235. Xif [ -s ${TMP3} ]
  236. Xthen
  237. X    for FILE in `cat ${TMP3}`
  238. X    do
  239. X        ls -ldg ${ODIR}/${FILE} >${TMP2}
  240. X        ls -ldg /${FILE} >>${TMP2}
  241. X        X=`${BASE}/ftype ${ORIG}/${FILE}`
  242. X        if [ -z "${X}" ]
  243. X        then
  244. X            echo "\n<original\n>current" >>${TMP2}
  245. X            diff ${ORIG}/${FILE} /${FILE}  >>${TMP2}
  246. X        else
  247. X            echo "\nChecksums:" >>${TMP2}
  248. X            sum ${ODIR}/${FILE} /${FILE} >>${TMP2}
  249. X        fi
  250. X        echo "\nlogins when change was noticed " >>${TMP2}
  251. X        who >>${TMP2}
  252. X        mail -s "/${FILE} changed" ${NOTIFY} <${TMP2}
  253. X    done
  254. X    COUNT=`wc -l ${TMP3} | cut -c1-8`
  255. X    COUNT=`echo ${COUNT}`
  256. Xelse
  257. X    COUNT=0
  258. Xfi
  259. X
  260. Xrm -f ${TMP1} ${TMP2} ${TMP3}
  261. X
  262. X#
  263. X# This last bit is for use with a system monitor program
  264. X# It reports the status to the parent
  265. X# 
  266. X
  267. Xecho "${COUNT} file\c"
  268. Xif [ ${COUNT} != 1 ]
  269. Xthen
  270. X    echo "s\c"
  271. Xfi
  272. Xecho " changed\c"
  273. X
  274. Xif [ ${COUNT} -gt 0 ]
  275. Xthen
  276. X    echo " (details mailed to ${NOTIFY})"
  277. Xelse
  278. X    echo
  279. Xfi
  280. Xexit
  281. SHAR_EOF
  282. chmod +x 'checkfiles'
  283. fi # end of overwriting check
  284. echo shar: extracting "'ftype.c'" '(2172 characters)'
  285. if test -f 'ftype.c'
  286. then
  287.     echo shar: will not over-write existing file "'ftype.c'"
  288. else
  289. sed 's/^X//' << \SHAR_EOF > 'ftype.c'
  290. X#include <stdio.h>
  291. X
  292. X/*    Atype.c  find numbers of different types of characters in
  293. X*    a file...Rich Kulawiec, 8/2/82  revised 10/86
  294. X*    Note that characters 200-377 octal are mapped down.
  295. X*
  296. X*    Modified by Paul Blackburn (mpb@mn.osf.org) to determine
  297. X*    if file is 'binary' (i.e. executable, directory) so that
  298. X*    diff could not be used on it.
  299. X*/
  300. X
  301. Xchar    *maptable[16][8] = { 
  302. X    "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
  303. X    "bs ", "ht ", "nl ", "vt ", "np ", "cr ", "so ", "si ",
  304. X    "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb",
  305. X    "can", "em ", "sub", "esc", "fs ", "gs ", "rs ", "us ",
  306. X    "sp ", " ! ", " \" "," # ", " $ ", " % ", " & ", " ' ",
  307. X    " ( ", " ) ", " * ", " + ", " , ", " - ", " . ", " / ", 
  308. X    " 0 ", " 1 ", " 2 ", " 3 ", " 4 ", " 5 ", " 6 ", " 7 ", 
  309. X    " 8 ", " 9 ", " : ", " ; ", " < ", " = ", " > ", " ? ", 
  310. X    " @ ", " A ", " B ", " C ", " D ", " E ", " F ", " G ", 
  311. X    " H ", " I ", " J ", " K ", " L ", " M ", " N ", " O ", 
  312. X    " P ", " Q ", " R ", " S ", " T ", " U ", " V ", " W ", 
  313. X    " X ", " Y ", " Z ", " [ ", " \\ ", " ] ", " ^ ", " _ ", 
  314. X    " ` ", " a ", " b ", " c ", " d ", " e ", " f ", " g ", 
  315. X    " h ", " i ", " j ", " k ", " l ", " m ", " n ", " o ", 
  316. X    " p ", " q ", " r ", " s ", " t ", " u ", " v ", " w ",
  317. X    " x ", " y ", " z ", " { ", " | ", " } ", " ~ ", "del" 
  318. X    } ;
  319. X
  320. Xint     count[8][16];
  321. X
  322. XFILE    *fp;
  323. XFILE    *fopen();
  324. X
  325. Xmain(argc, argv)
  326. Xint argc;
  327. Xchar *argv[];
  328. X{
  329. X    int c,i,j,k,nprint,nread;
  330. X
  331. X/* only need to read the first 128 bytes */
  332. X
  333. X    nread=0;
  334. X    if(argc == 1)
  335. X    {
  336. X        fp = stdin;
  337. X        while(((c = getc(fp)) != EOF) && (nread < 128))
  338. X        {
  339. X            count[ ((c&0177) % 8) ][ ((c&0177) / 8) ]++;
  340. X            nread++;
  341. X        }
  342. X    }
  343. X    else
  344. X    {
  345. X        for ( i = 1; i < argc;  i++)
  346. X        {
  347. X            if( (fp=fopen(argv[i],"r")) == NULL)
  348. X            {
  349. X                (void) fprintf(stderr,"atype: can't open %s\n",argv[i]);
  350. X                continue;
  351. X            }
  352. X            while(((c = getc(fp)) != EOF) && (nread < 128))
  353. X            {
  354. X                count[ ((c&0177) % 8) ][ ((c&0177) / 8) ]++;
  355. X                nread++;
  356. X            }
  357. X            (void) fclose(fp);
  358. X        }
  359. X    }
  360. X
  361. X    nprint=0;
  362. X    for(k=0; k<4; k++)
  363. X    {
  364. X        for(j=0; j<8; j++) 
  365. X            nprint+=count[j][k];
  366. X    }
  367. X    nprint-=count[1][1]; /* discount tabs */
  368. X    nprint-=count[2][1]; /* discount newlines */
  369. X    if (nprint > 0)
  370. X    {
  371. X        (void) printf("binary\n");
  372. X    }
  373. X}
  374. SHAR_EOF
  375. fi # end of overwriting check
  376. echo shar: extracting "'list'" '(700 characters)'
  377. if test -f 'list'
  378. then
  379.     echo shar: will not over-write existing file "'list'"
  380. else
  381. sed 's/^X//' << \SHAR_EOF > 'list'
  382. X# This file contains a list of files that are checked for changes (mpb21Oct89)
  383. X# (this is for an ULTRIX system, edit for other flavours)
  384. X
  385. X/.rhosts
  386. X/etc/exports
  387. X/etc/fstab
  388. X/etc/group
  389. X/etc/hosts
  390. X/etc/hosts.equiv
  391. X/etc/passwd
  392. X/etc/rc
  393. X/etc/rc.local
  394. X/usr/bin/login
  395. X/usr/bin/passwd
  396. X/usr/bin/su
  397. X/usr/lib/aliases
  398. X/usr/lib/crontab
  399. X/usr/lib/mail.aliases
  400. X/usr/lib/sendmail.cf
  401. X/usr/local/lib/syswatch
  402. X/usr/local/lib/watcher/Daemons
  403. X/usr/local/lib/watcher/OSFHosts
  404. X/usr/local/lib/watcher/Watcherfile
  405. X/usr/var/yp/src/group
  406. X/usr/var/yp/src/hosts
  407. X/usr/var/yp/src/netgroup
  408. X/usr/var/yp/src/networks
  409. X/usr/var/yp/src/passwd
  410. X/usr/var/yp/src/protocols
  411. X/usr/var/yp/src/rpc
  412. X/usr/var/yp/src/services
  413. X/usr/var/yp/src/ypservers
  414. SHAR_EOF
  415. fi # end of overwriting check
  416. echo shar: extracting "'resetfiles'" '(2009 characters)'
  417. if test -f 'resetfiles'
  418. then
  419.     echo shar: will not over-write existing file "'resetfiles'"
  420. else
  421. sed 's/^X//' << \SHAR_EOF > 'resetfiles'
  422. X#!/bin/sh5
  423. X# NAME        resetfiles
  424. X# AUTHOR    Paul Blackburn, OSF, Munich
  425. X# DATE        Sat Oct 21 11:52:05 MET 1989
  426. X# PURPOSE    Re-creates the reference copies for checkfiles to check against
  427. X
  428. XPATH=/usr/ucb:/bin:/usr/bin
  429. Xexport PATH
  430. XIFS="     
  431. X"
  432. Xexport IFS
  433. X
  434. XBASE=/users/mpb/masters
  435. XMASTER=osfmuc
  436. X
  437. XLIST=${BASE}/list
  438. XORIG=${BASE}/originals
  439. XMAKE=${BASE}/Makefile.re
  440. XTEMP=/usr/tmp/reset.$$
  441. XCMD=`basename ${0}`
  442. X
  443. Xif [ "${MASTER}" != "`uuname -l`" ]
  444. Xthen
  445. X    echo "Error: ${CMD} should be executed on ${MASTER}" >&2
  446. X    exit 1
  447. Xfi
  448. X
  449. Xif [ -d "${BASE}" ]
  450. Xthen
  451. X    cd $BASE
  452. Xelse
  453. X    echo "${CMD}: unable to cd to ${BASE}" >&2
  454. X    exit 1
  455. Xfi
  456. X
  457. XTMP1=/usr/tmp/tmp1.$$
  458. XTMP2=/usr/tmp/tmp2.$$
  459. XTMP3=/usr/tmp/tmp3.$$
  460. X
  461. Xif [ ! -z "${DEBUG}" ]
  462. Xthen
  463. X    echo "Extracting from list"
  464. Xfi
  465. X
  466. Xcd ${BASE}
  467. Xgrep -v "^#" <$LIST | sed -e "/^$/d" | cut -c2- | sort >${TMP1}
  468. X
  469. Xif [ ! -z "${DEBUG}" ]
  470. Xthen
  471. X    echo "Creating list from originals"
  472. Xfi
  473. X
  474. Xcd ${ORIG}
  475. Xfind . -type f -print | cut -c3- | sort >${TMP2}
  476. X
  477. Xif [ ! -z "${DEBUG}" ]
  478. Xthen
  479. X    echo "Comparing two lists"
  480. Xfi
  481. X
  482. Xcomm -13 ${TMP1} ${TMP2} >${TMP3}
  483. X
  484. Xif [ -s ${TMP3} ]
  485. Xthen
  486. X
  487. X    if [ ! -z "${DEBUG}" ]
  488. X    then
  489. X        echo "Removing unwanted files from originals"
  490. X    fi
  491. X
  492. X    <${TMP3} xargs -t rm -f
  493. Xfi
  494. X
  495. Xif [ ! -z "${DEBUG}" ]
  496. Xthen
  497. X    echo "Removing temporary files"
  498. Xfi
  499. X
  500. Xrm ${TMP1} ${TMP2} ${TMP3}
  501. X
  502. X# Create a Makefile from LIST
  503. X
  504. Xif [ ! -z "${DEBUG}" ]
  505. Xthen
  506. X    echo "Creating Makefile"
  507. Xfi
  508. X
  509. Xcat <<eeooff >$MAKE
  510. X# Makefile to rebuild original file copies
  511. X# generated by `uuname -l`:$USER on `date`
  512. X
  513. XORIG=${ORIG}
  514. X
  515. Xall:    \\
  516. Xeeooff
  517. X
  518. Xif [ ! -z "${DEBUG}" ]
  519. Xthen
  520. X    echo "Creating all dependencies"
  521. Xfi
  522. X
  523. Xgrep -v "^#" <$LIST \
  524. X| sed -e "/^$/d" \
  525. X| cut -c2- >${TEMP}
  526. X
  527. Xsed -e "s/.$/&\\\\/" <${TEMP}\
  528. X| sed -e "s,^.,\    \$(ORIG)/&," >>$MAKE
  529. X
  530. Xecho "\t${BASE}/README" >> $MAKE
  531. X
  532. Xwhile FILE=`line`
  533. Xdo
  534. X    cat <<eeooff >>$MAKE
  535. X
  536. X\$(ORIG)/${FILE}:    /$FILE
  537. X    cd /; echo ${FILE} | cpio -pdmuva \$(ORIG)
  538. Xeeooff
  539. Xdone <${TEMP}
  540. Xrm ${TEMP}
  541. X
  542. Xif [ ! -z "${DEBUG}" ]
  543. Xthen
  544. X    echo "Executing Makefile"
  545. Xfi
  546. X
  547. Xmake -f ${MAKE}
  548. X
  549. Xif [ ! -z "${DEBUG}" ]
  550. Xthen
  551. X    echo "Deleting Makefile"
  552. Xfi
  553. X
  554. Xrm ${MAKE}
  555. Xexit
  556. SHAR_EOF
  557. chmod +x 'resetfiles'
  558. fi # end of overwriting check
  559. if test ! -d 'originals'
  560. then
  561.     echo shar: creating directory "'originals'"
  562.     mkdir 'originals'
  563. fi
  564. echo shar: entering directory "'originals'"
  565. cd 'originals'
  566. echo shar: done with directory "'originals'"
  567. cd ..
  568. echo shar: done with directory "'checkfiles'"
  569. cd ..
  570. #    End of shell archive
  571. exit 0
  572.  
  573.